<template>
	<div>
		<div>
			<span><i class="el-icon-search el-icon--right"></i> 筛选查询</span>
			&nbsp;&nbsp;
			登记时间:
			<el-date-picker v-model="startime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
			</el-date-picker>&nbsp;到
			<el-date-picker v-model="endtime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
			</el-date-picker>
			&nbsp;&nbsp;
			项目:
			<el-select v-model="projectname" placeholder="请选择" clearable>
				<el-option v-for="item in project" :key="item.defectId" :label="item.projectName"
					:value="item.defectId">
				</el-option>
			</el-select>
			&nbsp;&nbsp;
			<el-button @click="Findit" style="margin-left: 200px;">查询<i class="el-icon-search el-icon--right"></i>
			</el-button>
		</div>
		<br>
		<div>
			<!-- 表格展示缺陷 -->
			<el-table ref="multipleTable" :data="defectrecord" tooltip-effect="dark" style="width: 100%">
				<el-table-column prop="defectId" label="编号">
				</el-table-column>
				<el-table-column prop="projectName" label="项目名称">
				</el-table-column>
				<el-table-column prop="defectName" label="缺陷名称" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="parentDefectId" label="父缺陷">
					<template slot-scope="scope">
						<span>{{scope.row.parentDefectId==0?'':scope.row.parentDefectId}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="defectPriority" label="优先级">
				</el-table-column>
				<el-table-column prop="defectSevsrity" label="严重程度">
				</el-table-column>
				<el-table-column prop="defectType" label="缺陷类别">
				</el-table-column>
				<el-table-column prop="issueState" label="状态">
				</el-table-column>
				<el-table-column prop="assignee" label="指派">
					<template slot-scope="scope">
						<span>{{scope.row.assignee==null?'暂未指派':scope.row.assignee}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="planEndTime" label="计划完成时间">
				</el-table-column>
				<el-table-column fixed="right" label="操作">
					<template slot-scope="scope">
						<el-button type="text" size="small" @click="Getfeedback(scope.row)">反馈</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-dialog title="添加反馈" :visible.sync="LookMessage" width="35%">
				<el-form ref="form" :model="DefectMessage" label-width="150px">
					<el-form-item label="项目名称:">
						<span>{{DefectMessage.projectName}}</span>
					</el-form-item>
					<el-form-item label="父级缺陷:">
						<span>{{DefectMessage.parentDefectName==null?'无':DefectMessage.parentDefectName}}</span>
					</el-form-item>
					<el-form-item label="缺陷名称:">
						<span>{{DefectMessage.defectName}}</span>
					</el-form-item>
					<el-form-item label="缺陷分类:">
						<span>{{DefectMessage.defectType}}</span>
					</el-form-item>
					<el-form-item label="严重程度:">
						<span>{{DefectMessage.defectSevsrity}}</span>
					</el-form-item>
					<el-form-item label="优先级:">
						<span>{{DefectMessage.defectPriority}}</span>
					</el-form-item>
					<el-form-item label="预期工时:">
						<span>{{DefectMessage.planWorkHours}}</span>
					</el-form-item>
					<el-form-item label="完成率:">
						<span>{{DefectMessage.doneRatio}}%</span>
					</el-form-item>
					<el-form-item label="计划开始时间:">
						<span>{{DefectMessage.planStartTime}}</span>
					</el-form-item>
					<el-form-item label="计划结束时间:">
						<span>{{DefectMessage.planEndTime}}</span>
					</el-form-item>
					<el-form-item label="缺陷描述:">
						<span>{{DefectMessage.defectDesc}}</span>
					</el-form-item>
					<el-form-item label="缺陷要求:">
						<span>{{DefectMessage.doneCondition}}</span>
					</el-form-item>
					<el-form-item label="指派:">
						<span>{{DefectMessage.assignee}}</span>
					</el-form-item>
					<el-form-item label="实际用时:">
						<span>{{DefectMessage.actWorkHours==null?0:DefectMessage.actWorkHours}} 小时</span>
					</el-form-item>
					反馈记录:
					<!-- <el-form-item label="反馈记录:"> -->
					<el-table :data="Feedbackrecord" style="width: 100%">
						<el-table-column prop="logId" label="反馈编号">
						</el-table-column>
						<el-table-column prop="logComment" label="反馈内容">
						</el-table-column>
						<el-table-column prop="createTime" label="反馈时间">
						</el-table-column>
					</el-table>
					<!-- </el-form-item> -->
					<el-form-item label="当前状态:">
						<el-select v-model="DefectMessage.issueState" placeholder="请选择">
							<el-option v-for="item in state" :key="item.stateId" :label="item.stateDesc"
								:value="item.stateDesc">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="缺陷反馈:">
						<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容"
							v-model="logComment">
						</el-input>
					</el-form-item>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button type="primary" @click="Addfeedback(DefectMessage)">确定</el-button>
					<el-button @click="LookMessage = false">取 消</el-button>
				</span>
			</el-dialog>
		</div>
		<div id="DS-Bottom">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pageInfo.current" :page-sizes="[1, 2, 3, 4]" :page-size="pageInfo.size"
				layout="total, sizes, prev, pager, next, jumper" :total="pageInfo.total">
			</el-pagination>
		</div>
	</div>
</template>

<script>
	export default {
		name: "defectfeeback",
		data() {
			return {
				defectrecord: [],
				current: 1,
				size: 3,
				projectname: "",
				endtime: "",
				startime: "",
				project: [],
				pageInfo: {},
				DefectMessage: {},
				sstate: "",
				state: [],
				Feedbackrecord: [],
				LookMessage: false,
				logComment:"",
				person:{}

			}
		},
		methods: {
			Addfeedback(defect){
				if(defect.assignee==this.person.accountName){
					this.$http.post("/comment/Addfeedback",{defectId:defect.defectId,logComment:this.logComment}).then(resp=>{
						if(resp.data.code==200){
							this.$message({
								message:resp.data.message,
								type:'success',
								duration:1000
							})
							this.LookMessage=false;
							this.GetDefectList(this.current, this.size, this.projectname, this.startime, this.endtime);
						}
					})
				}else{
					this.$message({
						message:"您不是"+defect.assignee+"不能反馈",
						type:'warning',
						duration:1000
					})
				}
				
			},
			Getfeedback(defect) {
					this.LookMessage = true
					this.$http.post("/defectRecord/HandleRecordById", {
						defectId: defect.defectId
					}).then(resp => {
						this.DefectMessage = resp.data.data;
						this.sstate = this.DefectMessage.issueState
					});
					this.$http.post("/comment/GetcommentByDefectId", {
						defectId: defect.defectId
					}).then(resp => {
						this.Feedbackrecord = resp.data.data
					})
			},
			Findit() {
				this.GetDefectList(this.current, this.size, this.projectname, this.startime, this.endtime);
			},
			handleSizeChange(val) {
				this.size = val;
				this.GetDefectList(this.current, val, this.projectname, this.startime, this.endtime);

			},
			handleCurrentChange(val) {
				this.current = val;
				this.GetDefectList(val, this.size, this.projectname, this.startime, this.endtime);
			},
			Getinfo() {
				this.$http.get("/defectRecord/GetAllDefectProject").then(resp => {
					this.project = resp.data.data;
				})
				this.$http.get("/defectState/GetAllDefectState").then(resp => {
					this.state = resp.data.data;
				})
			},
			GetDefectList(current, size, projectname, startime, endtime) {
				this.$http.post("/defectRecord/GetDefectRecordsByaccountId", {
					current: current,
					size: size,
					defectId: projectname,
					startime: startime,
					endtime: endtime
				}).then(resp => {
					this.pageInfo = resp.data.data;
					this.defectrecord = resp.data.data.records.filter(defect => defect.assignee != null).map(
						defect => defect);
				});
			}
		},
		created() {
			this.GetDefectList(this.current, this.size, this.projectname, this.startime, this.endtime);
			this.Getinfo()
			this.person=JSON.parse(localStorage.getItem("loginUser"))
		}
	}
</script>

<style>
	#DS-Bottom {
		position: absolute;
		text-align: right;
		bottom: 0;
		height: 35px;
		left: 0;
		right: 0;
	}
</style>
